package com.spring5.learning;

import com.spring5.learning.annotation.DefaultProfile;
import com.spring5.learning.annotation.DevProfile;
import com.spring5.learning.annotation.ProductProfile;
import com.spring5.learning.annotation.TestProfile;
import com.spring5.learning.env.Environment;
import com.spring5.learning.env.impl.DefaultEnvironment;
import com.spring5.learning.env.impl.DevEnvironment;
import com.spring5.learning.env.impl.ProductEnvironment;
import com.spring5.learning.env.impl.TestEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @author xin
 * @version 1.0
 */
@Configuration
@ComponentScan
@PropertySource("classpath:app.properties")
public class AppConfig {

    private final org.springframework.core.env.Environment env;

    @Autowired
    public AppConfig(org.springframework.core.env.Environment env) {
        this.env = env;
    }

    @Bean
    @DevProfile
    public Environment devEnvironment() {
        return new DevEnvironment();
    }

    @Bean
    @TestProfile
    public Environment testEnvironment() {
        return new TestEnvironment();
    }

    @Bean
    @ProductProfile
    public Environment productEnvironment() {
        return new ProductEnvironment();
    }

    @Bean
    @DefaultProfile
    public Environment defaultEnvironment() {
        System.out.println(env.getProperty("module.name"));
        //System.out.println(env.getProperty("module.no-exist"));
        return new DefaultEnvironment();
    }
}
